<template>
    <div class="tw_wrape">
        <div class="tw_inner">
            <div class="tw_top ">
                <div class="tw_title">选择日期</div>
                <div class="tw_week">
                    <div class="tw_between_color">日</div>
                    <div>一</div>
                    <div>二</div>
                    <div>三</div>
                    <div>四</div>
                    <div>五</div>
                    <div class="tw_between_color">六</div>
                </div>
            </div>
            <div v-for="(items,j) in source" :key="j">
                <div class="item_header">2018年6月</div>
                <div class="tw_date_list">
                    <div class="tw_date_item" :class="{'tw_between_color' : item.end}" v-for="(item,i) in items" v-bind:key="i">{{item.day}}</div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
const weeks = ["日","壹","弍","叁","肆","伍","陆"];
export default {
    name: 'my-date',
    data(){
        return{
            data:"",
            day:"",
            ddd:"2018-03-28",
            source:[]
        }
    },
    mounted(){
        // let c_time = new Date(); // 获取当前时间;
        // let c_year= c_time.getFullYear(); // 获取当前年份;
        // let c_month = c_time.getMonth()+1; // 获取当前月份;
        // let c_date = c_time.getDate(); // 获取今天几号;
        // let c_day = c_time.getDay(); // 获取今天周几;

        // var allSource = [];
       
        // this.source = this.getMouthSource(c_year,c_month,c_date);
        this.getSource();
    },
    methods:{
        getMouthSource(c_year,c_month,c_date){
            let t_date = new Date(c_year,c_month,0);
            let t_days = t_date.getDate(); // 获取这个月有几天
            let startWeek = new Date(c_year,c_month-1,1).getDay(); //当月第一天是周几
            var arr = [];
            for(let i=0; i<t_days+startWeek; i++){
                let obj = {};
                obj.day = "";
                obj.click = false;
                obj.end = false;
                obj.select = false;
                if(i>=startWeek){
                    obj.day = i-startWeek+1;
                    if(i+1 == c_date+startWeek){
                        obj.day = "今天";
                    }
                    obj.click = true;
                    if(i%7 == 0 || (i+1)%7 == 0){
                        obj.end = true;
                    }
                }
                arr.push(obj);
            }
            return arr;
        },
        getSource(){
            var allSource = [];
            let c_time = new Date(); // 获取当前时间;
            let c_year= c_time.getFullYear(); // 获取当前年份;
            let c_month = c_time.getMonth()+1; // 获取当前月份;
            let c_date = c_time.getDate(); // 获取今天几号;
            let c_day = c_time.getDay(); // 获取今天周几;

            for(let j=c_month; j<c_month + 6; j++){
                let t_date = new Date(c_year,j,0);
                let t_days = t_date.getDate(); // 获取这个月有几天
                let startWeek = new Date(c_year,j-1,1).getDay(); //当月第一天是周几
                var arr = [];
                for(let i=0; i<t_days+startWeek; i++){
                    let obj = {};
                    obj.day = "";
                    obj.click = false;
                    obj.end = false;
                    obj.select = false;
                    if(i>=startWeek){
                        obj.day = i-startWeek+1;
                        if(i+1 == c_date+startWeek && j == c_month){
                            obj.day = "今天";
                        }
                        obj.click = true;
                        if(i%7 == 0 || (i+1)%7 == 0){
                            obj.end = true;
                        }
                    }
                    arr.push(obj);
                }
                allSource.push(arr);
            }
            console.log(allSource);
            this.source = allSource;
        }
    }    
}
</script>
<style scoped>
    .tw_wrape{
        position: absolute;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.3);
        text-align: center;
        box-sizing: border-box;
        padding-top: 20vh;
        color: #333333;
    }
    .tw_title{
        font-size: 34px;
        line-height: 80px;
        font-weight: 500;
    
    }
    .tw_week{
        font-size: 26px;
        display: flex;
        justify-content: space-around;
        align-items: center;
        height: 60px;
    }
    .tw_30{
        font-size: 0.3rem;
    }
    .tw_between_color{
        color: #FF3C00;
    }
    .tw_inner{
        background: #ffffff;
        height: 80vh;
        width: 100vw;
    }
    .item_header{
        height: 63px;
        font-size: 30px;
        text-align: center;
        line-height: 63px;
        background: #F1F2F6;
    }
    .tw_date_list{
        display: flex;
        flex-wrap: wrap;
        padding: 0 4px;
        box-sizing: border-box;
    }
    .tw_date_item{
        width: 106px;
        height: 106px;
        text-align: center;
        line-height: 106px;
        font-size: 32px;
        border-radius: 6px; /*no*/
    }
</style>
